pushNotificationReceived
Type
message
Summary
Sent when the application receives a push notification from a Push Notification Server.
Syntax
pushNotificationReceived <pMessage>
Description
Handles the pushNotificationReceived message to perform an action when the device receives a push notification message from a server for the application.
The pushNotificationReceived message is handled once the application receives a push notification from a Push Notification Server.
Depending on the status of the application, iOS can launch a dialog box or open the login screen to inform the user that an application has information for them. Android can create an application icon in the status bar. The user can then decide whether or not to open the application. If the application is opened as a result of the notification, then LiveCode can handle the message. If an application is currently running when it receives a notification, then LiveCode can handle the message and process it as required.
When running on Android 13 and above, applications which send push notifications must check that the user has granted the necessary permission to do so and request it if not.
This could be done, for example, when the user enables an app feature which requires such
notifications, or on startup of the app, in the app's main openStack
handler, using the
following code:
if the platform is \"android\" and the systemVersion >= 13 then
local tPostNotificationsPermissionGranted
put androidHasPermission(\"android.permission.POST_NOTIFICATIONS\") \
into tPostNotificationsPermissionGranted
if not tPostNotificationsPermissionGranted then
androidRequestPermission \"android.permission.POST_NOTIFICATIONS\"
end if
put androidHasPermission(\"android.permission.POST_NOTIFICATIONS\") \
into tPostNotificationsPermissionGranted
if not tPostNotificationsPermissionGranted then
answer \"This app is not permitted to post notifications. You can change this\" && \
\"in the Settings app.\"
end if
end if
If a badge number is received with the notification, then that badge value is displayed on the applications icon (iOS only), but only if the application is not currently running. If the application is running, then a badge value update does not take place, as the application can handle the message without being launched.
Parameters
Name | Type | Description |
---|---|---|
pMessage | The Notification Message received. This is text that was submitted when the message was scheduled with the Push Notification Server. |
Examples
on pushNotificationReceived pMessage
answer "Push Notification:" && quote & pMessage & quote with "Okay"
end pushNotificationReceived
Related
command: iphoneSetNotificationBadgeValue
function: iphoneGetNotificationBadgeValue, mobileGetDeviceToken
message: pushNotificationRegistered, pushNotificationRegistrationError
Compatibility and Support
Introduced
LiveCode 5.5
OS
ios
android
Platforms
mobile